//the white cactus grew under the tape, with wind, stars and the sunflowers outside...
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define endl '\n'
int cas,n,m,k,vol,ans1,ans2,d[100009],v[100009],a[100009],x[100009],pre[1000009],mxl[1000009],dp[1000009],q[1000009];
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>cas;
    while(cas--){
        cin>>n>>m>>k>>vol;k++;
        ans1=0;ans2=m;
        for(int i=1;i<=k+5;i++)pre[i]=mxl[i]=0;
        for(int i=1;i<=m+5;i++)dp[i]=q[i]=0;
        for(int i=1;i<=n;i++)cin>>d[i]>>v[i]>>a[i],d[i]++;
        for(int i=1;i<=m;i++)cin>>x[i],pre[++x[i]]++;
        for(int i=1;i<=k;i++)pre[i]+=pre[i-1];
        for(int i=1;i<=n;i++){
            if(a[i]>0){
                int p;
                if(v[i]>vol)p=d[i];
                else p=(vol*vol-v[i]*v[i])/(2*a[i])+1+d[i];
                if(p<=k&&pre[k]-pre[p-1])ans1++,mxl[k+1]=max(mxl[k+1],p);
            }else if(a[i]<0){
                a[i]=-a[i];int p;
                if(v[i]<=vol)continue;
                p=min(k,(v[i]*v[i]-vol*vol+2*a[i]-1)/(2*a[i])+d[i]-1);
                if(pre[p]-pre[d[i]-1])ans1++,mxl[p+1]=max(mxl[p+1],d[i]);
                // cerr<<i<<' '<<p<<endl;
            }else{
                if(v[i]>vol&&pre[k]-pre[d[i]-1])ans1++,mxl[k+1]=max(mxl[k+1],d[i]);
            }
        }
        for(int i=1;i<=k+5;i++)mxl[i]=max(mxl[i],mxl[i-1]);
        // for(int i=1;i<=k+1;i++)cerr<<i<<' '<<mxl[i]<<endl;
        for(int i=0,hd=1,tl=0;i<=m;i++){
            while(hd<=tl&&mxl[x[i]]>x[q[hd]])hd++;
            if(hd<=tl)dp[i]=dp[q[hd]]+1;
            while(hd<=tl&&dp[i]<=dp[q[tl]])tl--;
            q[++tl]=i;
            // cerr<<i<<' '<<dp[i]<<' '<<mxl[x[i]]<<' '<<(lower_bound(x+1,x+1+m,mxl[x[i]])-x)<<endl;
            if(x[i]>=mxl[k+1])ans2=min(ans2,dp[i]);
        }
        cout<<ans1<<' '<<m-ans2<<endl;
    }
    return 0;
}